package Common

import (
	"../ProtoGo"
	"../Robot"
	"github.com/golang/protobuf/proto"
)

//RegisterErrorHandler 处理错误协议方法
func RegisterErrorHandler(r *Robot.Robot) {
	r.RobotLog("注册错误处理模块")

	cc := Cmd.Command_ERROR_USER_PROTOCMD.Enum()

	pp := Cmd.ErrCmdParam_REG_ERR_USER_CMD.Enum()
	r.Handler.RegisterHandle(byte(*cc), byte(*pp), handleRegErrUserCmd)
}

func handleRegErrUserCmd(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.RegErrUserCmd{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化RegErrUserCmd")
	} else {
		robot.RobotLog(response.String())
	}
}
